package com.winz.cultureapp.application;

import android.app.Application;
import android.content.Context;

import com.mob.MobSDK;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.winz.cultureapp.constants.Constants;
import com.winz.cultureapp.utils.MyToast;
import com.winz.cultureapp.utils.SharePrefsUtil;

/**
 * 自定义Application
 */
public class DemoApplication extends Application {
    public static Context applicationContext;
    private static DemoApplication mApplication;

    public static int cur_source = 0;//
    public static double cur_money = 0.0;// 充值金额

    public MyToast toast;
    /**
     * 用于测试时
     */
    public static final boolean isTest = false;

    public boolean isLogin = false; // 是否是有登录
    public boolean isAdmin = false; // 是否是管理员

    // 微信

    // IWXAPI 是第三方app和微信通信的openApi接口
    public static IWXAPI api;

    @Override
    public void onCreate() {
        super.onCreate();
        // ShareSDK
        MobSDK.init(this);

        mApplication = this;
        applicationContext = this;
        toast = new MyToast(this);
        initPrefs();

        // 通过WXAPIFactory工厂，获取IWXAPI的实例
        api = WXAPIFactory.createWXAPI(this, Constants.APP_INFO.WX.AppID, true);

        // 将应用的appId注册到微信
        api.registerApp(Constants.APP_INFO.WX.AppID);
    }

    public static synchronized DemoApplication getInstance() {
        return mApplication;
    }

    @Override
    public void onTerminate() {
        // 程序终止的时候执行
        super.onTerminate();
        toast.cancel();
    }
    /**
     * 初始化SharedPreference
     */
    protected void initPrefs() {
        SharePrefsUtil.init(getApplicationContext(), getPackageName() + "_preference", Context.MODE_MULTI_PROCESS);
    }

}
